package org.xshop.web.sys;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xshop.core.JPushHelper;
import org.xshop.model.SysNews;
import org.xshop.service.ISysNewsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import top.ibase4j.core.base.BaseController;

/**
 * 新闻管理控制类
 *
 * @author ShenHuaJie
 * @version 2016年5月20日 下午3:13:31
 */
@RestController
@Api(value = "新闻管理", description = "新闻管理")
@RequestMapping(value = "news")
public class SysNewsController extends BaseController<SysNews, ISysNewsService> {
    @Autowired
    private JPushHelper jpushHelper;
    @Override
    @ApiOperation(value = "查询新闻")
    @RequiresPermissions("sys.cms.news.read")
    @PutMapping(value = "/read/list")
    public Object query(ModelMap modelMap, @RequestBody Map<String, Object> param) {
        return super.query(modelMap, param);
    }

    @ApiOperation(value = "新闻详情")
    @RequiresPermissions("sys.cms.news.read")
    @PutMapping(value = "/read/detail")
    public Object get(ModelMap modelMap, @RequestBody SysNews param) {
        return super.get(modelMap, param);
    }

    @Override
    @PostMapping
    @ApiOperation(value = "修改新闻")
    @RequiresPermissions("sys.cms.news.update")
    public Object update(ModelMap modelMap, @RequestBody SysNews param) {
        if (param.getStatus() == null) {
            param.setStatus("0");
        }
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("type", "2");
        jpushHelper.aliasMessageAll(param.getNewsTitle(), "系统通知", hashMap);
        return super.update(modelMap, param);
    }

    @Override
    @DeleteMapping
    @ApiOperation(value = "删除新闻")
    @RequiresPermissions("sys.cms.news.delete")
    public Object delete(ModelMap modelMap, @RequestBody SysNews param) {
        return super.delete(modelMap, param);
    }
}
